package com.study.jyg.rxjava2study.activity.design;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.os.Bundle;
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.widget.ImageView;

import com.study.jyg.rxjava2study.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * design 动画
 */
public class DesignAnimationActivity extends AppCompatActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.iv1)
    ImageView iv1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_design_animation);
        ButterKnife.bind(this);


    }

    /**
     * 揭露动画
     */
    private void startAnima(View view) {
        //主要代码
        int width = view.getMeasuredWidth();
        int height = view.getMeasuredHeight();
        //参数1 view， 2 x轴半径， 3 y轴半径 4 开始时半径 5 结束时半径
        Animator animator = ViewAnimationUtils.createCircularReveal(view, width, height, (float) Math.sqrt(width * width + height * height), 0);
        animator.setDuration(10000);//动画时长
        animator.setStartDelay(1000);//动画延迟执行时长
        animator.setInterpolator(new LinearOutSlowInInterpolator());//插补器有没有不影响//out到in
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {


            }
        });
        animator.start();
    }

    @OnClick(R.id.iv1)
    public void onViewClicked() {
        startAnima(iv1);
    }
}
